package domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name= "book_classes")
@NamedQueries({
	@NamedQuery(name = "BookClass.findAll", query = "SELECT b FROM BookClass b")
})
public class BookClass implements Serializable {

	private static final long serialVersionUID = 1L;
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	int id;
	@Column(name="name", nullable = false)
	String name;
	@Column(name="author")
	String author;
	@Column(name="genre")
	String genre;
	@Column(name="description")
	String description;
	@Column(name="rent")
	double rent;
	@Column(name="mortgage")
	double mortgage;
	
	/*  
	@OneToMany(mappedBy = "books")
	List<Book> instances;
	*/
	
	public BookClass() {}
	
	public BookClass(int id, String name, String author, String genre,
			String description, double rent, double mortgage) {
		this.id = id;
		this.name = name;
		this.author = author;
		this.genre = genre;
		this.description = description;
		this.rent = rent;
		this.mortgage = mortgage;
	}
	
	public BookClass(String name, String author, String genre,
			String description, double rent, double mortgage) {
		this.name = name;
		this.author = author;
		this.genre = genre;
		this.description = description;
		this.rent = rent;
		this.mortgage = mortgage;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getGenre() {
		return genre;
	}
	public void setGenre(String genre) {
		this.genre = genre;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public double getRent() {
		return rent;
	}
	public void setRent(double rent) {
		this.rent = rent;
	}
	public double getMortgage() {
		return mortgage;
	}
	public void setMortgage(double mortgage) {
		this.mortgage = mortgage;
	}
	@Override
	public String toString() {
		return "("+id + ") " + name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((author == null) ? 0 : author.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((genre == null) ? 0 : genre.hashCode());
		result = prime * result + id;
		long temp;
		temp = Double.doubleToLongBits(mortgage);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		temp = Double.doubleToLongBits(rent);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BookClass other = (BookClass) obj;
		if (author == null) {
			if (other.author != null)
				return false;
		} else if (!author.equals(other.author))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (genre == null) {
			if (other.genre != null)
				return false;
		} else if (!genre.equals(other.genre))
			return false;
		if (id != other.id)
			return false;
		if (Double.doubleToLongBits(mortgage) != Double
				.doubleToLongBits(other.mortgage))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (Double.doubleToLongBits(rent) != Double
				.doubleToLongBits(other.rent))
			return false;
		return true;
	}
	
	
}
